﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using BOHVote.BLL;

namespace BOH.Reports
{
    public partial class SubjectHeightReport : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["ApplyPeriod"] != null)
                {
                    string AccreditationLevel = "G";
                    if (!string.IsNullOrEmpty(Request["al"]))
                        AccreditationLevel = Request["al"].ToString();
                    labPeriod.Text = Session["ApplyPeriod"].ToString();
                    if (AccreditationLevel == "S")
                        labLevel.Text = "社区";
                    else
                        labLevel.Text = "高评";
                    labPeriod.Text = Session["ApplyPeriod"].ToString();
                    ShowReport(Session["ApplyPeriod"].ToString(), AccreditationLevel);
                }

            }

        }

        public void ShowReport(string strApplyPeriod,string strAccreditationLevel)
        {
            DataSet dst = ReportClass.dstSubjectHeightApply(strApplyPeriod, strAccreditationLevel);

            string SubjectTotal = "合计";
            int AllTotalApply = 0, AllTotalPass = 0, AllHeightApply = 0, AllHeightPass = 0, AllHeightApplyN = 0, AllHeightPassN = 0, AllHeightApplyB = 0, AllHeightPassB = 0;
            int AllviceApply = 0, AllvicePass = 0, AllviceApplyN = 0, AllvicePassN = 0, AllviceApplyB = 0, AllvicePassB = 0;

            double AllTotalPassRate = 0, AllHeightPassRate = 0, AllHeightPassNRate = 0, AllHeightPassBRate = 0, AllvicePassRate = 0, AllvicePassNRate = 0, AllvicePassBRate = 0;

            foreach(DataRow dr in dst.Tables[0].Rows)
            {
                HtmlTableRow row = new HtmlTableRow();
                row.Style.Add("height", "22px");
                HtmlTableCell cell1 = new HtmlTableCell();
                cell1.InnerText = dr["SequenceNo"].ToString();
                cell1.Align = "Center";
                row.Cells.Add(cell1);

                HtmlTableCell cell2 = new HtmlTableCell();
                cell2.InnerText = dr["SubjectID"].ToString();
                cell2.Align = "Center";
                row.Cells.Add(cell2);

                HtmlTableCell cell3 = new HtmlTableCell();
                cell3.InnerText = dr["SubjectName"].ToString();
                cell3.Align = "Center";
                row.Cells.Add(cell3);

                #region <<  所有申报  >>
                if (!String.IsNullOrEmpty(dr["TotalApply"].ToString())&&dr["TotalApply"].ToString().Trim() != "0")
                {
                    HtmlTableCell cell4 = new HtmlTableCell();
                    cell4.InnerText = dr["TotalApply"].ToString();
                    cell4.Align = "Center";
                    cell4.Style.Add("font-weight", "bold");
                    cell4.Style.Add("background-color", "#ffff99");
                    row.Cells.Add(cell4);

                    HtmlTableCell cell5 = new HtmlTableCell();
                    cell5.InnerText = dr["TotalPass"].ToString();
                    cell5.Align = "Center";
                    cell5.Style.Add("font-weight", "bold");
                    row.Cells.Add(cell5);

                    HtmlTableCell cell6 = new HtmlTableCell();
                    cell6.InnerText = dr["TotalPassRate"].ToString() + "%";
                    cell6.Align = "right";
                    cell6.Style.Add("font-weight", "bold");
                    row.Cells.Add(cell6);

                    AllTotalApply += Convert.ToInt32(dr["TotalApply"].ToString());
                    AllTotalPass += Convert.ToInt32(dr["TotalPass"].ToString());
                }
                else
                {
                    HtmlTableCell cell4 = new HtmlTableCell();
                    cell4.InnerText = "";
                    cell4.Style.Add("background-color", "#ffff99");
                    row.Cells.Add(cell4);

                    HtmlTableCell cell5 = new HtmlTableCell();
                    cell5.InnerText = "";
                    row.Cells.Add(cell5);

                    HtmlTableCell cell6 = new HtmlTableCell();
                    cell6.InnerText = "";
                    row.Cells.Add(cell6);
                }
                #endregion

                #region  <<  正高申报  >>
                if (!String.IsNullOrEmpty(dr["HeightApply"].ToString())&&dr["HeightApply"].ToString().Trim() != "0")
                {

                    HtmlTableCell cell7 = new HtmlTableCell();
                    cell7.InnerText = dr["HeightApply"].ToString();
                    cell7.Align = "Center";
                    cell7.Style.Add("font-weight", "bold");
                    cell7.Style.Add("background-color", "#99ccff");
                    row.Cells.Add(cell7);

                    HtmlTableCell cell8 = new HtmlTableCell();
                    cell8.InnerText = dr["HeightPass"].ToString();
                    cell8.Align = "Center";
                    cell8.Style.Add("font-weight", "bold");
                    row.Cells.Add(cell8);

                    HtmlTableCell cell9 = new HtmlTableCell();
                    cell9.InnerText = dr["HeightPassRate"].ToString() + "%";
                    cell9.Align = "right";
                    cell9.Style.Add("font-weight", "bold");
                    row.Cells.Add(cell9);

                    AllHeightApply += Convert.ToInt32(dr["HeightApply"].ToString());
                    AllHeightPass += Convert.ToInt32(dr["HeightPass"].ToString());
                }
                else
                {
                    HtmlTableCell cell7 = new HtmlTableCell();
                    cell7.InnerText = "";
                    cell7.Style.Add("background-color", "#99ccff");
                    row.Cells.Add(cell7);

                    HtmlTableCell cell8 = new HtmlTableCell();
                    cell8.InnerText = "";
                    row.Cells.Add(cell8);

                    HtmlTableCell cell9 = new HtmlTableCell();
                    cell9.InnerText = "";
                    row.Cells.Add(cell9);
                }
                #endregion

#region <<  正高 正常>>

                if (!String.IsNullOrEmpty(dr["HeightApplyN"].ToString()) && dr["HeightApplyN"].ToString() != "0")
                {

                    HtmlTableCell cell10 = new HtmlTableCell();
                    cell10.InnerText = dr["HeightApplyN"].ToString();
                    cell10.Align = "Center";
                    cell10.Style.Add("font-weight", "bold");
                    cell10.Style.Add("background-color", "#99ccff");
                    row.Cells.Add(cell10);

                    HtmlTableCell cell11 = new HtmlTableCell();
                    cell11.InnerText = dr["HeightPassN"].ToString();
                    cell11.Align = "Center";
                    cell11.Style.Add("font-weight", "bold");
                    row.Cells.Add(cell11);

                    HtmlTableCell cell12 = new HtmlTableCell();
                    cell12.InnerText = dr["HeightPassRateN"].ToString() + "%";
                    cell12.Align = "right";
                    cell12.Style.Add("font-weight", "bold");
                    row.Cells.Add(cell12);

                    AllHeightApplyN += Convert.ToInt32(dr["HeightApplyN"].ToString());
                    AllHeightPassN += Convert.ToInt32(dr["HeightPassN"].ToString());
                }
                else
                {
                    HtmlTableCell cell10 = new HtmlTableCell();
                    cell10.InnerText = "";
                    cell10.Style.Add("background-color", "#99ccff");
                    row.Cells.Add(cell10);

                    HtmlTableCell cell11 = new HtmlTableCell();
                    cell11.InnerText = "";
                    row.Cells.Add(cell11);

                    HtmlTableCell cell12 = new HtmlTableCell();
                    cell12.InnerText = "";
                    row.Cells.Add(cell12);
                }
#endregion

#region << 正高 破格  >>
                if (!String.IsNullOrEmpty(dr["HeightApplyB"].ToString()) && dr["HeightApplyB"].ToString().Trim() != "0")
                {

                    HtmlTableCell cell13 = new HtmlTableCell();
                    cell13.InnerText = dr["HeightApplyB"].ToString();
                    cell13.Align = "Center";
                    cell13.Style.Add("font-weight", "bold");
                    cell13.Style.Add("background-color", "#99ccff");
                    row.Cells.Add(cell13);

                    HtmlTableCell cell14 = new HtmlTableCell();
                    cell14.InnerText = dr["HeightPassB"].ToString();
                    cell14.Align = "Center";
                    cell14.Style.Add("font-weight", "bold");
                    row.Cells.Add(cell14);

                    HtmlTableCell cell15 = new HtmlTableCell();
                    cell15.InnerText = dr["HeightPassRateB"].ToString() + "%";
                    cell15.Align = "right";
                    cell15.Style.Add("font-weight", "bold");
                    row.Cells.Add(cell15);

                    AllHeightApplyB += Convert.ToInt32(dr["HeightApplyB"].ToString());
                    AllHeightPassB += Convert.ToInt32(dr["HeightPassB"].ToString());
                }
                else
                {
                    HtmlTableCell cell13 = new HtmlTableCell();
                    cell13.InnerText = "";
                    cell13.Style.Add("background-color", "#99ccff");
                    row.Cells.Add(cell13);

                    HtmlTableCell cell14 = new HtmlTableCell();
                    cell14.InnerText = "";
                    row.Cells.Add(cell14);

                    HtmlTableCell cell15 = new HtmlTableCell();
                    cell15.InnerText = "";
                    row.Cells.Add(cell15);
                }
#endregion

#region <<  副高 申报  >>
                if (!String.IsNullOrEmpty(dr["viceApply"].ToString()) && dr["viceApply"].ToString().Trim() != "0")
                {
                    HtmlTableCell cell16 = new HtmlTableCell();
                    cell16.InnerText = dr["viceApply"].ToString();
                    cell16.Align = "Center";
                    cell16.Style.Add("font-weight", "bold");
                    cell16.Style.Add("background-color", "#ffcc99");
                    row.Cells.Add(cell16);

                    HtmlTableCell cell17 = new HtmlTableCell();
                    cell17.InnerText = dr["vicePass"].ToString();
                    cell17.Align = "Center";
                    cell17.Style.Add("font-weight", "bold");
                    row.Cells.Add(cell17);

                    HtmlTableCell cell18 = new HtmlTableCell();
                    cell18.InnerText = dr["vicePassRate"].ToString() + "%";
                    cell18.Align = "right";
                    cell18.Style.Add("font-weight", "bold");
                    row.Cells.Add(cell18);

                    AllviceApply += Convert.ToInt32(dr["viceApply"].ToString());
                    AllvicePass += Convert.ToInt32(dr["vicePass"].ToString());
                }
                else
                {
                    HtmlTableCell cell16 = new HtmlTableCell();
                    cell16.InnerText ="";
                    cell16.Style.Add("background-color", "#ffcc99");
                    row.Cells.Add(cell16);

                    HtmlTableCell cell17 = new HtmlTableCell();
                    cell17.InnerText = "";
                    row.Cells.Add(cell17);

                    HtmlTableCell cell18 = new HtmlTableCell();
                    cell18.InnerText = "";
                    row.Cells.Add(cell18);
                }
#endregion

#region  <<  副高 正常  >>
                if (!String.IsNullOrEmpty(dr["viceApplyN"].ToString()) && dr["viceApplyN"].ToString().Trim() != "0")
                {
                    HtmlTableCell cell19 = new HtmlTableCell();
                    cell19.InnerText = dr["viceApplyN"].ToString();
                    cell19.Align = "Center";
                    cell19.Style.Add("font-weight", "bold");
                    cell19.Style.Add("background-color", "#ffcc99");
                    row.Cells.Add(cell19);

                    HtmlTableCell cell20 = new HtmlTableCell();
                    cell20.InnerText = dr["vicePassN"].ToString();
                    cell20.Align = "Center";
                    cell20.Style.Add("font-weight", "bold");
                    row.Cells.Add(cell20);

                    HtmlTableCell cell21 = new HtmlTableCell();
                    cell21.InnerText = dr["vicePassRateN"].ToString() + "%";
                    cell21.Align = "right";
                    cell21.Style.Add("font-weight", "bold");
                    row.Cells.Add(cell21);

                    AllviceApplyN += Convert.ToInt32(dr["viceApplyN"].ToString());
                    AllvicePassN += Convert.ToInt32(dr["vicePassN"].ToString());
                }
                else
                {
                    HtmlTableCell cell19 = new HtmlTableCell();
                    cell19.InnerText ="";
                    cell19.Style.Add("background-color", "#ffcc99");
                    row.Cells.Add(cell19);

                    HtmlTableCell cell20 = new HtmlTableCell();
                    cell20.InnerText = "";
                    row.Cells.Add(cell20);

                    HtmlTableCell cell21 = new HtmlTableCell();
                    cell21.InnerText = "";
                    row.Cells.Add(cell21);
                }
#endregion

#region  <<  副高 破格  >>
                if (!String.IsNullOrEmpty(dr["viceApplyB"].ToString()) && dr["viceApplyB"].ToString().Trim() != "0")
                {
                    HtmlTableCell cell22 = new HtmlTableCell();
                    cell22.InnerText = dr["viceApplyB"].ToString();
                    cell22.Align = "Center";
                    cell22.Style.Add("font-weight", "bold");
                    cell22.Style.Add("background-color", "#ffcc99");
                    row.Cells.Add(cell22);

                    HtmlTableCell cell23 = new HtmlTableCell();
                    cell23.InnerText = dr["vicePassB"].ToString();
                    cell23.Align = "Center";
                    cell23.Style.Add("font-weight", "bold");
                    row.Cells.Add(cell23);

                    HtmlTableCell cell24 = new HtmlTableCell();
                    cell24.InnerText = dr["vicePassRateB"].ToString() + "%";
                    cell24.Align = "right";
                    cell24.Style.Add("font-weight", "bold");
                    row.Cells.Add(cell24);

                    AllviceApplyB += Convert.ToInt32(dr["viceApplyB"].ToString());
                    AllvicePassB += Convert.ToInt32(dr["vicePassB"].ToString());
                }
                else
                {
                    HtmlTableCell cell22 = new HtmlTableCell();
                    cell22.InnerText = "";
                    cell22.Style.Add("background-color", "#ffcc99");
                    row.Cells.Add(cell22);

                    HtmlTableCell cell23 = new HtmlTableCell();
                    cell23.InnerText = "";
                    row.Cells.Add(cell23);

                    HtmlTableCell cell24 = new HtmlTableCell();
                    cell24.InnerText = "";
                    row.Cells.Add(cell24);
                }
#endregion
                tabSubjectReport.Rows.Add(row);
            }

            #region  <<  Add Total row  >>
            HtmlTableRow rowTotal = new HtmlTableRow();

            if (AllTotalApply != 0 && AllTotalPass != 0)
            {
                AllTotalPassRate = Convert.ToDouble(AllTotalPass) / Convert.ToDouble(AllTotalApply);
            }
            else
            {
                AllTotalPassRate = 0;
            }

            if (AllHeightApply != 0 && AllHeightPass != 0)
            {
                AllHeightPassRate = Convert.ToDouble(AllHeightPass) / Convert.ToDouble(AllHeightApply);
            }
            else
            {
                AllHeightPassRate = 0;
            }

            if (AllHeightApplyN != 0 && AllHeightPassN != 0)
            {
                AllHeightPassNRate = Convert.ToDouble(AllHeightPassN) / Convert.ToDouble(AllHeightApplyN);
            }
            else
            {
                AllHeightPassNRate = 0;
            }

            if (AllHeightApplyB != 0 && AllHeightPassB != 0)
            {
                AllHeightPassBRate = Convert.ToDouble(AllHeightPassB) / Convert.ToDouble(AllHeightPassB);
            }
            else
            {
                AllHeightPassBRate = 0;
            }


            if (AllviceApply != 0 && AllvicePass != 0)
            {
                AllvicePassRate = Convert.ToDouble(AllvicePass) / Convert.ToDouble(AllviceApply);
            }
            else
            {
                AllvicePassRate = 0;
            }

            if (AllviceApplyN != 0 && AllvicePassN != 0)
            {
                AllvicePassNRate = Convert.ToDouble(AllvicePassN) / Convert.ToDouble(AllviceApplyN);
            }
            else
            {
                AllvicePassNRate = 0;
            }

            if (AllviceApplyB != 0 && AllvicePassB != 0)
            {
                AllvicePassBRate = Convert.ToDouble(AllvicePassB) / Convert.ToDouble(AllviceApplyB);
            }
            else
            {
                AllvicePassBRate = 0;
            }

            HtmlTableCell cella = new HtmlTableCell();
            cella.InnerText = string.Empty;
            rowTotal.Cells.Add(cella);

            HtmlTableCell cellb = new HtmlTableCell();
            cellb.InnerText = string.Empty;
            rowTotal.Cells.Add(cellb);

            HtmlTableCell cellc = new HtmlTableCell();
            cellc.InnerText = SubjectTotal;
            cellc.Style.Add("font-weight", "bold");
            rowTotal.Cells.Add(cellc);

            HtmlTableCell celld = new HtmlTableCell();
            celld.InnerText = AllTotalApply.ToString();
            celld.Style.Add("background-color", "#ffff99");
            celld.Style.Add("font-weight", "bold");
            rowTotal.Cells.Add(celld);

            HtmlTableCell celle = new HtmlTableCell();
            celle.InnerText = AllTotalPass.ToString();
            celle.Style.Add("font-weight", "bold");
            rowTotal.Cells.Add(celle);

            HtmlTableCell cellf = new HtmlTableCell();
            cellf.InnerText = AllTotalPassRate.ToString("0.00%");
            cellf.Style.Add("font-weight", "bold");
            rowTotal.Cells.Add(cellf);

            HtmlTableCell cellg = new HtmlTableCell();
            cellg.InnerText = AllHeightApply.ToString();
            cellg.Style.Add("background-color", "#99ccff");
            cellg.Style.Add("font-weight", "bold");
            rowTotal.Cells.Add(cellg);

            HtmlTableCell cellh = new HtmlTableCell();
            cellh.InnerText = AllHeightPass.ToString();
            cellh.Style.Add("font-weight", "bold");
            rowTotal.Cells.Add(cellh);

            HtmlTableCell celli = new HtmlTableCell();
            celli.InnerText = AllHeightPassRate.ToString("0.00%");
            celli.Style.Add("font-weight", "bold");
            rowTotal.Cells.Add(celli);

            HtmlTableCell cellj = new HtmlTableCell();
            cellj.InnerText = AllHeightApplyN.ToString();
            cellj.Style.Add("background-color", "#99ccff");
            cellj.Style.Add("font-weight", "bold");
            rowTotal.Cells.Add(cellj);

            HtmlTableCell cellk = new HtmlTableCell();
            cellk.InnerText = AllHeightPassN.ToString();
            cellk.Style.Add("font-weight", "bold");
            rowTotal.Cells.Add(cellk);

            HtmlTableCell celll = new HtmlTableCell();
            celll.InnerText = AllHeightPassNRate.ToString("0.00%");
            celll.Style.Add("font-weight", "bold");
            rowTotal.Cells.Add(celll);

            HtmlTableCell cello = new HtmlTableCell();
            cello.InnerText = AllHeightApplyB.ToString();
            cello.Style.Add("background-color", "#99ccff");
            cello.Style.Add("font-weight", "bold");
            rowTotal.Cells.Add(cello);

            HtmlTableCell cellp = new HtmlTableCell();
            cellp.InnerText = AllHeightPassB.ToString();
            cellp.Style.Add("font-weight", "bold");
            rowTotal.Cells.Add(cellp);

            HtmlTableCell cellp1 = new HtmlTableCell();
            cellp1.InnerText = AllHeightPassBRate.ToString("0.00%");
            cellp1.Style.Add("font-weight", "bold");
            rowTotal.Cells.Add(cellp1);

            HtmlTableCell cellq = new HtmlTableCell();
            cellq.InnerText = AllviceApply.ToString();
            cellq.Style.Add("background-color", "#ffcc99");
            cellq.Style.Add("font-weight", "bold");
            rowTotal.Cells.Add(cellq);

            HtmlTableCell cellu = new HtmlTableCell();
            cellu.InnerText = AllvicePass.ToString();
            cellu.Style.Add("font-weight", "bold");
            rowTotal.Cells.Add(cellu);

            HtmlTableCell cellV = new HtmlTableCell();
            cellV.InnerText = AllvicePassRate.ToString("0.00%");
            cellV.Style.Add("font-weight", "bold");
            rowTotal.Cells.Add(cellV);

            HtmlTableCell cellw = new HtmlTableCell();
            cellw.InnerText = AllviceApplyN.ToString();
            cellw.Style.Add("background-color", "#ffcc99");
            cellw.Style.Add("font-weight", "bold");
            rowTotal.Cells.Add(cellw);

            HtmlTableCell cellx = new HtmlTableCell();
            cellx.InnerText = AllvicePassN.ToString();
            cellx.Style.Add("font-weight", "bold");
            rowTotal.Cells.Add(cellx);

            HtmlTableCell celly = new HtmlTableCell();
            celly.InnerText = AllvicePassNRate.ToString("0.00%");
            celly.Style.Add("font-weight", "bold");
            rowTotal.Cells.Add(celly);

            HtmlTableCell cellz = new HtmlTableCell();
            cellz.InnerText = AllviceApplyB.ToString();
            cellz.Style.Add("background-color", "#ffcc99");
            cellz.Style.Add("font-weight", "bold");
            rowTotal.Cells.Add(cellz);

            HtmlTableCell cellz1 = new HtmlTableCell();
            cellz1.InnerText = AllvicePassB.ToString();
            cellz1.Style.Add("font-weight", "bold");
            rowTotal.Cells.Add(cellz1);

            HtmlTableCell celly1 = new HtmlTableCell();
            celly1.InnerText = AllvicePassBRate.ToString("0.00%");
            celly1.Style.Add("font-weight", "bold");
            rowTotal.Cells.Add(celly1);

            tabSubjectReport.Rows.Add(rowTotal);
            #endregion
        }

        //protected void butExecl_Click(object sender, EventArgs e)
        //{
        //    common.ToExcel(GovernList);
        //}


        //public override void VerifyRenderingInServerForm(Control control)
        //{
        //}
    }
}
